package arsmodeller.commands;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;

import arsmodeller.model.ObjectProcessDiagram;
import arsmodeller.model.ObjectProcessingDiagram;
import arsmodeller.model.Thing;

public class ThingCreateCommand extends Command {
	private static final Dimension defaultDimension = new Dimension(50, 50);
	private static final String defaultName = "<...>";

	private Thing newThing;
	private Rectangle constraints;
	private ObjectProcessingDiagram opd;

	@Override
	public void execute() {
		newThing.setName(defaultName);
		if (constraints != null) {
			newThing.setConstraints(constraints);
		}
		newThing.setOpd(opd);
	}

	@Override
	public void undo() {
		newThing.setOpd(null);
	}

	public void setLocation(Point location) {
		constraints = new Rectangle(location, defaultDimension);
	}

	public void setParent(ObjectProcessingDiagram opd) {
		this.opd = opd;
	}

	public void setThing(Thing newThing) {
		this.newThing = newThing;
	}

}
